<!DOCTYPE html>
<html lang="en-US">
  
<!-- Mirrored from heavy_code_industry.gitee.io/code_heavy_industry/pro009-Nginx/snapshot/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 10 May 2022 04:34:45 GMT -->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>代码重工</title>
    <meta name="generator" content="VuePress 1.9.5">
    
    <meta name="description" content="代码重工">
    
    <link rel="preload" href="../../assets/css/0.styles.f7de6701.css" as="style"><link rel="preload" href="../../assets/js/app.972bd0f0.js" as="script"><link rel="preload" href="../../assets/js/4.904e76b5.js" as="script"><link rel="preload" href="../../assets/js/16.87793b5d.js" as="script"><link rel="prefetch" href="../../assets/js/1.d66e04b2.js"><link rel="prefetch" href="../../assets/js/10.7093d550.js"><link rel="prefetch" href="../../assets/js/100.384331b2.js"><link rel="prefetch" href="../../assets/js/101.582f78e7.js"><link rel="prefetch" href="../../assets/js/102.17f2c0ec.js"><link rel="prefetch" href="../../assets/js/103.a530857d.js"><link rel="prefetch" href="../../assets/js/104.62821ce1.js"><link rel="prefetch" href="../../assets/js/105.11cdcc82.js"><link rel="prefetch" href="../../assets/js/106.d57c1e75.js"><link rel="prefetch" href="../../assets/js/107.7ebeb306.js"><link rel="prefetch" href="../../assets/js/108.c067b47b.js"><link rel="prefetch" href="../../assets/js/109.9495d2ca.js"><link rel="prefetch" href="../../assets/js/11.acc2935e.js"><link rel="prefetch" href="../../assets/js/110.7f58dbd3.js"><link rel="prefetch" href="../../assets/js/111.f78239ff.js"><link rel="prefetch" href="../../assets/js/112.8eb72445.js"><link rel="prefetch" href="../../assets/js/113.3f5aff71.js"><link rel="prefetch" href="../../assets/js/114.9f65cf57.js"><link rel="prefetch" href="../../assets/js/115.dcaea004.js"><link rel="prefetch" href="../../assets/js/116.726c5aac.js"><link rel="prefetch" href="../../assets/js/117.54d6c26a.js"><link rel="prefetch" href="../../assets/js/118.3f4e0bda.js"><link rel="prefetch" href="../../assets/js/119.95ed5dc6.js"><link rel="prefetch" href="../../assets/js/12.a5354f50.js"><link rel="prefetch" href="../../assets/js/120.4fd08fac.js"><link rel="prefetch" href="../../assets/js/121.f4aadbe5.js"><link rel="prefetch" href="../../assets/js/122.d588a1e0.js"><link rel="prefetch" href="../../assets/js/123.781e7192.js"><link rel="prefetch" href="../../assets/js/124.ed312291.js"><link rel="prefetch" href="../../assets/js/125.bceffbb9.js"><link rel="prefetch" href="../../assets/js/126.51bf552f.js"><link rel="prefetch" href="../../assets/js/127.4800687b.js"><link rel="prefetch" href="../../assets/js/128.fcdd6f2a.js"><link rel="prefetch" href="../../assets/js/129.2a25d78a.js"><link rel="prefetch" href="../../assets/js/13.88a0c565.js"><link rel="prefetch" href="../../assets/js/130.dcfe7623.js"><link rel="prefetch" href="../../assets/js/131.c29e7c45.js"><link rel="prefetch" href="../../assets/js/132.9a412a4b.js"><link rel="prefetch" href="../../assets/js/133.615218d5.js"><link rel="prefetch" href="../../assets/js/134.2168ca5a.js"><link rel="prefetch" href="../../assets/js/135.a5e262ff.js"><link rel="prefetch" href="../../assets/js/136.7dba5235.js"><link rel="prefetch" href="../../assets/js/137.445576e7.js"><link rel="prefetch" href="../../assets/js/138.577b3f66.js"><link rel="prefetch" href="../../assets/js/139.b646f1ac.js"><link rel="prefetch" href="../../assets/js/14.36391765.js"><link rel="prefetch" href="../../assets/js/140.52abf81e.js"><link rel="prefetch" href="../../assets/js/141.807c626b.js"><link rel="prefetch" href="../../assets/js/142.adf9e127.js"><link rel="prefetch" href="../../assets/js/143.9773d979.js"><link rel="prefetch" href="../../assets/js/144.5658ae76.js"><link rel="prefetch" href="../../assets/js/145.2d2fb13b.js"><link rel="prefetch" href="../../assets/js/146.0e322019.js"><link rel="prefetch" href="../../assets/js/147.50b34ac1.js"><link rel="prefetch" href="../../assets/js/148.463aab7c.js"><link rel="prefetch" href="../../assets/js/149.9bd7c539.js"><link rel="prefetch" href="../../assets/js/15.4a8e9d28.js"><link rel="prefetch" href="../../assets/js/150.9449ca28.js"><link rel="prefetch" href="../../assets/js/151.1961c6db.js"><link rel="prefetch" href="../../assets/js/152.18709656.js"><link rel="prefetch" href="../../assets/js/153.a4bf78f6.js"><link rel="prefetch" href="../../assets/js/154.6c90b1d5.js"><link rel="prefetch" href="../../assets/js/155.024247e2.js"><link rel="prefetch" href="../../assets/js/156.76281b57.js"><link rel="prefetch" href="../../assets/js/157.a7c02212.js"><link rel="prefetch" href="../../assets/js/158.0d00acef.js"><link rel="prefetch" href="../../assets/js/159.9180c937.js"><link rel="prefetch" href="../../assets/js/160.d7a98288.js"><link rel="prefetch" href="../../assets/js/161.389ddf84.js"><link rel="prefetch" href="../../assets/js/162.ab22d7dc.js"><link rel="prefetch" href="../../assets/js/163.087257c6.js"><link rel="prefetch" href="../../assets/js/164.addfc5af.js"><link rel="prefetch" href="../../assets/js/165.f90e6b2a.js"><link rel="prefetch" href="../../assets/js/166.fa06e4b6.js"><link rel="prefetch" href="../../assets/js/167.a00e722b.js"><link rel="prefetch" href="../../assets/js/168.e3855223.js"><link rel="prefetch" href="../../assets/js/169.e0c63a4e.js"><link rel="prefetch" href="../../assets/js/17.dec86310.js"><link rel="prefetch" href="../../assets/js/170.7c5835f4.js"><link rel="prefetch" href="../../assets/js/171.7d9ae110.js"><link rel="prefetch" href="../../assets/js/172.4da5caea.js"><link rel="prefetch" href="../../assets/js/173.f8ac6155.js"><link rel="prefetch" href="../../assets/js/174.3b831765.js"><link rel="prefetch" href="../../assets/js/175.01782f3d.js"><link rel="prefetch" href="../../assets/js/176.6eab6644.js"><link rel="prefetch" href="../../assets/js/177.86339767.js"><link rel="prefetch" href="../../assets/js/178.c437c804.js"><link rel="prefetch" href="../../assets/js/179.927227c9.js"><link rel="prefetch" href="../../assets/js/18.9167733d.js"><link rel="prefetch" href="../../assets/js/180.caa2c660.js"><link rel="prefetch" href="../../assets/js/181.c186b8ac.js"><link rel="prefetch" href="../../assets/js/182.0475844f.js"><link rel="prefetch" href="../../assets/js/183.2c5950c8.js"><link rel="prefetch" href="../../assets/js/184.82b336f6.js"><link rel="prefetch" href="../../assets/js/185.e2d4a46e.js"><link rel="prefetch" href="../../assets/js/186.99a3de8a.js"><link rel="prefetch" href="../../assets/js/187.d557500c.js"><link rel="prefetch" href="../../assets/js/188.e81bd251.js"><link rel="prefetch" href="../../assets/js/189.d07d368a.js"><link rel="prefetch" href="../../assets/js/19.017b4ad0.js"><link rel="prefetch" href="../../assets/js/190.173606ea.js"><link rel="prefetch" href="../../assets/js/191.c5ac0c71.js"><link rel="prefetch" href="../../assets/js/192.127d6d93.js"><link rel="prefetch" href="../../assets/js/193.2f9011c9.js"><link rel="prefetch" href="../../assets/js/194.14f534a3.js"><link rel="prefetch" href="../../assets/js/195.65939036.js"><link rel="prefetch" href="../../assets/js/196.6e3cf025.js"><link rel="prefetch" href="../../assets/js/197.4d18b1d7.js"><link rel="prefetch" href="../../assets/js/198.c2e521c3.js"><link rel="prefetch" href="../../assets/js/199.d72c63dd.js"><link rel="prefetch" href="../../assets/js/20.6aa686d0.js"><link rel="prefetch" href="../../assets/js/200.56d7dbd3.js"><link rel="prefetch" href="../../assets/js/201.c72a395d.js"><link rel="prefetch" href="../../assets/js/202.cb32f7af.js"><link rel="prefetch" href="../../assets/js/203.285e6b92.js"><link rel="prefetch" href="../../assets/js/204.ead50027.js"><link rel="prefetch" href="../../assets/js/205.190c1baf.js"><link rel="prefetch" href="../../assets/js/206.4dab4ba0.js"><link rel="prefetch" href="../../assets/js/207.f11eee48.js"><link rel="prefetch" href="../../assets/js/208.e2f8ca82.js"><link rel="prefetch" href="../../assets/js/209.e7e74aff.js"><link rel="prefetch" href="../../assets/js/21.f7d66fe8.js"><link rel="prefetch" href="../../assets/js/210.69c4a0ed.js"><link rel="prefetch" href="../../assets/js/211.a1ab5062.js"><link rel="prefetch" href="../../assets/js/212.6d0473bd.js"><link rel="prefetch" href="../../assets/js/213.bd120419.js"><link rel="prefetch" href="../../assets/js/214.c7d4362c.js"><link rel="prefetch" href="../../assets/js/215.8adc34dc.js"><link rel="prefetch" href="../../assets/js/216.abf8ff23.js"><link rel="prefetch" href="../../assets/js/217.10f9fc46.js"><link rel="prefetch" href="../../assets/js/218.52e31fec.js"><link rel="prefetch" href="../../assets/js/219.ea0551af.js"><link rel="prefetch" href="../../assets/js/22.b1de9b18.js"><link rel="prefetch" href="../../assets/js/220.6be520c8.js"><link rel="prefetch" href="../../assets/js/221.c0d93576.js"><link rel="prefetch" href="../../assets/js/222.1bb0eaff.js"><link rel="prefetch" href="../../assets/js/223.8492b065.js"><link rel="prefetch" href="../../assets/js/224.5897434e.js"><link rel="prefetch" href="../../assets/js/225.51902428.js"><link rel="prefetch" href="../../assets/js/226.9da70eee.js"><link rel="prefetch" href="../../assets/js/227.9e113839.js"><link rel="prefetch" href="../../assets/js/228.d689b27d.js"><link rel="prefetch" href="../../assets/js/229.28f74090.js"><link rel="prefetch" href="../../assets/js/23.e3b58d3d.js"><link rel="prefetch" href="../../assets/js/230.465a35a0.js"><link rel="prefetch" href="../../assets/js/231.219aeb63.js"><link rel="prefetch" href="../../assets/js/232.84035c50.js"><link rel="prefetch" href="../../assets/js/233.ef27424d.js"><link rel="prefetch" href="../../assets/js/234.5dcf1349.js"><link rel="prefetch" href="../../assets/js/235.bcc0c537.js"><link rel="prefetch" href="../../assets/js/236.9bb64465.js"><link rel="prefetch" href="../../assets/js/237.f3300514.js"><link rel="prefetch" href="../../assets/js/238.ca7af9ac.js"><link rel="prefetch" href="../../assets/js/239.fdfe2127.js"><link rel="prefetch" href="../../assets/js/24.2e010582.js"><link rel="prefetch" href="../../assets/js/240.8a4488af.js"><link rel="prefetch" href="../../assets/js/241.9987dfab.js"><link rel="prefetch" href="../../assets/js/242.819ed984.js"><link rel="prefetch" href="../../assets/js/243.bf129ecd.js"><link rel="prefetch" href="../../assets/js/244.030b4b49.js"><link rel="prefetch" href="../../assets/js/245.7663f620.js"><link rel="prefetch" href="../../assets/js/246.ed2b2fc0.js"><link rel="prefetch" href="../../assets/js/247.54dd84f1.js"><link rel="prefetch" href="../../assets/js/248.a1c69038.js"><link rel="prefetch" href="../../assets/js/249.47dd7b3b.js"><link rel="prefetch" href="../../assets/js/25.a5f2f737.js"><link rel="prefetch" href="../../assets/js/250.ec8017a5.js"><link rel="prefetch" href="../../assets/js/251.89ab0cf7.js"><link rel="prefetch" href="../../assets/js/252.5ec1eea4.js"><link rel="prefetch" href="../../assets/js/253.31a37280.js"><link rel="prefetch" href="../../assets/js/254.fcfabb55.js"><link rel="prefetch" href="../../assets/js/255.286f4c17.js"><link rel="prefetch" href="../../assets/js/256.ce77595b.js"><link rel="prefetch" href="../../assets/js/257.cb3677c0.js"><link rel="prefetch" href="../../assets/js/258.ca18e0e9.js"><link rel="prefetch" href="../../assets/js/259.65dc8492.js"><link rel="prefetch" href="../../assets/js/26.cce346fc.js"><link rel="prefetch" href="../../assets/js/260.475ddaba.js"><link rel="prefetch" href="../../assets/js/261.643b784a.js"><link rel="prefetch" href="../../assets/js/262.e5092c67.js"><link rel="prefetch" href="../../assets/js/263.5e85d32e.js"><link rel="prefetch" href="../../assets/js/264.6ff4b789.js"><link rel="prefetch" href="../../assets/js/265.fee7416a.js"><link rel="prefetch" href="../../assets/js/266.8d8a5e44.js"><link rel="prefetch" href="../../assets/js/267.8c62a655.js"><link rel="prefetch" href="../../assets/js/268.762073ff.js"><link rel="prefetch" href="../../assets/js/269.ffe69921.js"><link rel="prefetch" href="../../assets/js/27.22790cda.js"><link rel="prefetch" href="../../assets/js/270.d5bf783f.js"><link rel="prefetch" href="../../assets/js/271.83fd2f70.js"><link rel="prefetch" href="../../assets/js/272.6de67fa9.js"><link rel="prefetch" href="../../assets/js/273.628e1b77.js"><link rel="prefetch" href="../../assets/js/274.7f0d82c6.js"><link rel="prefetch" href="../../assets/js/275.d4478098.js"><link rel="prefetch" href="../../assets/js/276.56649e5b.js"><link rel="prefetch" href="../../assets/js/277.05b881f2.js"><link rel="prefetch" href="../../assets/js/278.c079de28.js"><link rel="prefetch" href="../../assets/js/279.58101972.js"><link rel="prefetch" href="../../assets/js/28.ac0ba3fa.js"><link rel="prefetch" href="../../assets/js/280.5e32c770.js"><link rel="prefetch" href="../../assets/js/281.59fb6cf4.js"><link rel="prefetch" href="../../assets/js/282.f22da512.js"><link rel="prefetch" href="../../assets/js/283.db103d63.js"><link rel="prefetch" href="../../assets/js/284.a373c7e0.js"><link rel="prefetch" href="../../assets/js/285.55c6f720.js"><link rel="prefetch" href="../../assets/js/286.f924c38c.js"><link rel="prefetch" href="../../assets/js/287.52a35525.js"><link rel="prefetch" href="../../assets/js/288.dcc32270.js"><link rel="prefetch" href="../../assets/js/289.835ad2b5.js"><link rel="prefetch" href="../../assets/js/29.6e1dc238.js"><link rel="prefetch" href="../../assets/js/290.749e38a9.js"><link rel="prefetch" href="../../assets/js/291.90916822.js"><link rel="prefetch" href="../../assets/js/292.b453b275.js"><link rel="prefetch" href="../../assets/js/293.11ad0754.js"><link rel="prefetch" href="../../assets/js/294.dddc45b9.js"><link rel="prefetch" href="../../assets/js/295.74ecca38.js"><link rel="prefetch" href="../../assets/js/296.2061efa6.js"><link rel="prefetch" href="../../assets/js/297.b838fcd5.js"><link rel="prefetch" href="../../assets/js/298.8c08be1f.js"><link rel="prefetch" href="../../assets/js/299.5a99490b.js"><link rel="prefetch" href="../../assets/js/3.9ca9fb75.js"><link rel="prefetch" href="../../assets/js/30.64f9cad0.js"><link rel="prefetch" href="../../assets/js/300.a5010762.js"><link rel="prefetch" href="../../assets/js/301.a2f8795a.js"><link rel="prefetch" href="../../assets/js/302.129bdff3.js"><link rel="prefetch" href="../../assets/js/303.57268b2c.js"><link rel="prefetch" href="../../assets/js/304.5556b94f.js"><link rel="prefetch" href="../../assets/js/305.72bbf9b8.js"><link rel="prefetch" href="../../assets/js/306.821163a7.js"><link rel="prefetch" href="../../assets/js/307.b85ceac7.js"><link rel="prefetch" href="../../assets/js/308.7f794216.js"><link rel="prefetch" href="../../assets/js/309.212b7a1d.js"><link rel="prefetch" href="../../assets/js/31.386297cc.js"><link rel="prefetch" href="../../assets/js/310.089b4a08.js"><link rel="prefetch" href="../../assets/js/311.c7f6aabd.js"><link rel="prefetch" href="../../assets/js/312.810271c0.js"><link rel="prefetch" href="../../assets/js/313.030424f0.js"><link rel="prefetch" href="../../assets/js/314.a95451b6.js"><link rel="prefetch" href="../../assets/js/315.f883b88e.js"><link rel="prefetch" href="../../assets/js/316.676ed945.js"><link rel="prefetch" href="../../assets/js/317.0dcbeaef.js"><link rel="prefetch" href="../../assets/js/318.bd172af6.js"><link rel="prefetch" href="../../assets/js/319.e2d01ca1.js"><link rel="prefetch" href="../../assets/js/32.8927ba28.js"><link rel="prefetch" href="../../assets/js/320.09b01482.js"><link rel="prefetch" href="../../assets/js/321.3b70dce2.js"><link rel="prefetch" href="../../assets/js/322.5f7046ad.js"><link rel="prefetch" href="../../assets/js/323.ffd56783.js"><link rel="prefetch" href="../../assets/js/324.cfe0b188.js"><link rel="prefetch" href="../../assets/js/325.cc2f1112.js"><link rel="prefetch" href="../../assets/js/326.635a861b.js"><link rel="prefetch" href="../../assets/js/327.94eacc0e.js"><link rel="prefetch" href="../../assets/js/328.7d4790fb.js"><link rel="prefetch" href="../../assets/js/329.38f7ef56.js"><link rel="prefetch" href="../../assets/js/33.bd1f28e6.js"><link rel="prefetch" href="../../assets/js/330.269edfe2.js"><link rel="prefetch" href="../../assets/js/331.21623a36.js"><link rel="prefetch" href="../../assets/js/332.1f1c659c.js"><link rel="prefetch" href="../../assets/js/333.fe34384d.js"><link rel="prefetch" href="../../assets/js/334.34a514a7.js"><link rel="prefetch" href="../../assets/js/335.9272b0cc.js"><link rel="prefetch" href="../../assets/js/336.796dcaf9.js"><link rel="prefetch" href="../../assets/js/337.bfd29430.js"><link rel="prefetch" href="../../assets/js/338.fdb020fd.js"><link rel="prefetch" href="../../assets/js/339.d7f19890.js"><link rel="prefetch" href="../../assets/js/34.36a2460a.js"><link rel="prefetch" href="../../assets/js/340.b22b3f52.js"><link rel="prefetch" href="../../assets/js/341.47e1d3f4.js"><link rel="prefetch" href="../../assets/js/342.38ca17d1.js"><link rel="prefetch" href="../../assets/js/343.2e7874e5.js"><link rel="prefetch" href="../../assets/js/344.6697aea1.js"><link rel="prefetch" href="../../assets/js/345.ad3be23a.js"><link rel="prefetch" href="../../assets/js/346.d40fa749.js"><link rel="prefetch" href="../../assets/js/347.881934aa.js"><link rel="prefetch" href="../../assets/js/348.2e8d29b9.js"><link rel="prefetch" href="../../assets/js/349.87f51cb4.js"><link rel="prefetch" href="../../assets/js/35.80f36815.js"><link rel="prefetch" href="../../assets/js/350.06081b68.js"><link rel="prefetch" href="../../assets/js/351.f883c9ae.js"><link rel="prefetch" href="../../assets/js/352.8fcd0728.js"><link rel="prefetch" href="../../assets/js/353.2dd787b0.js"><link rel="prefetch" href="../../assets/js/354.689db664.js"><link rel="prefetch" href="../../assets/js/355.b9a083ea.js"><link rel="prefetch" href="../../assets/js/356.3eaa4bf3.js"><link rel="prefetch" href="../../assets/js/357.2f05ac11.js"><link rel="prefetch" href="../../assets/js/358.c6777610.js"><link rel="prefetch" href="../../assets/js/359.2ae0c8ac.js"><link rel="prefetch" href="../../assets/js/36.f9bba134.js"><link rel="prefetch" href="../../assets/js/360.c9811603.js"><link rel="prefetch" href="../../assets/js/361.5c3068d4.js"><link rel="prefetch" href="../../assets/js/362.a80ddcc6.js"><link rel="prefetch" href="../../assets/js/363.ccbb8d6e.js"><link rel="prefetch" href="../../assets/js/364.8da5de40.js"><link rel="prefetch" href="../../assets/js/365.0d9f6c8a.js"><link rel="prefetch" href="../../assets/js/366.e410e582.js"><link rel="prefetch" href="../../assets/js/367.f8689b17.js"><link rel="prefetch" href="../../assets/js/368.57119763.js"><link rel="prefetch" href="../../assets/js/369.f92c7aed.js"><link rel="prefetch" href="../../assets/js/37.8935c848.js"><link rel="prefetch" href="../../assets/js/370.8e896c3a.js"><link rel="prefetch" href="../../assets/js/371.e2565759.js"><link rel="prefetch" href="../../assets/js/372.0028b0ce.js"><link rel="prefetch" href="../../assets/js/373.82bfe997.js"><link rel="prefetch" href="../../assets/js/374.434f814f.js"><link rel="prefetch" href="../../assets/js/375.8478c681.js"><link rel="prefetch" href="../../assets/js/376.998ce2de.js"><link rel="prefetch" href="../../assets/js/377.670e9be5.js"><link rel="prefetch" href="../../assets/js/378.c9cfc01b.js"><link rel="prefetch" href="../../assets/js/379.0aacc719.js"><link rel="prefetch" href="../../assets/js/38.86fba1a7.js"><link rel="prefetch" href="../../assets/js/380.14a91411.js"><link rel="prefetch" href="../../assets/js/381.9e783c93.js"><link rel="prefetch" href="../../assets/js/382.cf2ffc03.js"><link rel="prefetch" href="../../assets/js/383.c32b0740.js"><link rel="prefetch" href="../../assets/js/384.4280025f.js"><link rel="prefetch" href="../../assets/js/385.a816d541.js"><link rel="prefetch" href="../../assets/js/386.1d8fc395.js"><link rel="prefetch" href="../../assets/js/387.bc22626f.js"><link rel="prefetch" href="../../assets/js/388.1cf59352.js"><link rel="prefetch" href="../../assets/js/389.a09795bf.js"><link rel="prefetch" href="../../assets/js/39.c8c0ff8e.js"><link rel="prefetch" href="../../assets/js/390.6a223692.js"><link rel="prefetch" href="../../assets/js/391.733d45f0.js"><link rel="prefetch" href="../../assets/js/392.d76fd3df.js"><link rel="prefetch" href="../../assets/js/393.c885df90.js"><link rel="prefetch" href="../../assets/js/394.c344d389.js"><link rel="prefetch" href="../../assets/js/395.687cbd0a.js"><link rel="prefetch" href="../../assets/js/396.57e0df54.js"><link rel="prefetch" href="../../assets/js/397.1a31ad36.js"><link rel="prefetch" href="../../assets/js/398.59535325.js"><link rel="prefetch" href="../../assets/js/399.0a11557f.js"><link rel="prefetch" href="../../assets/js/40.c0f7e504.js"><link rel="prefetch" href="../../assets/js/400.7b2afabb.js"><link rel="prefetch" href="../../assets/js/401.4b72ea6e.js"><link rel="prefetch" href="../../assets/js/402.b94737bf.js"><link rel="prefetch" href="../../assets/js/403.a838c189.js"><link rel="prefetch" href="../../assets/js/404.9a221abc.js"><link rel="prefetch" href="../../assets/js/405.f8f3b954.js"><link rel="prefetch" href="../../assets/js/406.2de8752c.js"><link rel="prefetch" href="../../assets/js/407.eb35a188.js"><link rel="prefetch" href="../../assets/js/408.47acaedf.js"><link rel="prefetch" href="../../assets/js/409.aa2afaca.js"><link rel="prefetch" href="../../assets/js/41.e7e858c4.js"><link rel="prefetch" href="../../assets/js/410.722e5009.js"><link rel="prefetch" href="../../assets/js/411.2dbe321f.js"><link rel="prefetch" href="../../assets/js/412.39ed2d1e.js"><link rel="prefetch" href="../../assets/js/413.a088f973.js"><link rel="prefetch" href="../../assets/js/414.87f8d239.js"><link rel="prefetch" href="../../assets/js/415.f90a1394.js"><link rel="prefetch" href="../../assets/js/416.ea4ba38d.js"><link rel="prefetch" href="../../assets/js/417.8a1c9676.js"><link rel="prefetch" href="../../assets/js/418.79315748.js"><link rel="prefetch" href="../../assets/js/419.1e3ddf12.js"><link rel="prefetch" href="../../assets/js/42.8202bb44.js"><link rel="prefetch" href="../../assets/js/420.b6d9e0cb.js"><link rel="prefetch" href="../../assets/js/421.0c74ef64.js"><link rel="prefetch" href="../../assets/js/422.94c20620.js"><link rel="prefetch" href="../../assets/js/423.fa0d6946.js"><link rel="prefetch" href="../../assets/js/424.9036ac4f.js"><link rel="prefetch" href="../../assets/js/425.8d8e82da.js"><link rel="prefetch" href="../../assets/js/426.03b7da89.js"><link rel="prefetch" href="../../assets/js/427.e3c8c690.js"><link rel="prefetch" href="../../assets/js/428.96fdfdce.js"><link rel="prefetch" href="../../assets/js/429.a8863be5.js"><link rel="prefetch" href="../../assets/js/43.55e30ded.js"><link rel="prefetch" href="../../assets/js/430.305aa090.js"><link rel="prefetch" href="../../assets/js/431.e02d3725.js"><link rel="prefetch" href="../../assets/js/432.83fa148f.js"><link rel="prefetch" href="../../assets/js/433.1f01715d.js"><link rel="prefetch" href="../../assets/js/434.f3354ec6.js"><link rel="prefetch" href="../../assets/js/435.245644ed.js"><link rel="prefetch" href="../../assets/js/436.3c933a14.js"><link rel="prefetch" href="../../assets/js/437.b62325fb.js"><link rel="prefetch" href="../../assets/js/438.8e122783.js"><link rel="prefetch" href="../../assets/js/439.e95fa7e6.js"><link rel="prefetch" href="../../assets/js/44.e5c90e7a.js"><link rel="prefetch" href="../../assets/js/440.5c168090.js"><link rel="prefetch" href="../../assets/js/441.f8835ac7.js"><link rel="prefetch" href="../../assets/js/442.cf1de5dc.js"><link rel="prefetch" href="../../assets/js/443.50ec8b3c.js"><link rel="prefetch" href="../../assets/js/444.1600e74f.js"><link rel="prefetch" href="../../assets/js/445.795f336d.js"><link rel="prefetch" href="../../assets/js/446.1fb71b0f.js"><link rel="prefetch" href="../../assets/js/447.0136df19.js"><link rel="prefetch" href="../../assets/js/448.abf11aa4.js"><link rel="prefetch" href="../../assets/js/449.4f99bee8.js"><link rel="prefetch" href="../../assets/js/45.89368cde.js"><link rel="prefetch" href="../../assets/js/450.55da381a.js"><link rel="prefetch" href="../../assets/js/451.97a68e8d.js"><link rel="prefetch" href="../../assets/js/452.9dd8c55e.js"><link rel="prefetch" href="../../assets/js/453.3167da0d.js"><link rel="prefetch" href="../../assets/js/454.18fad993.js"><link rel="prefetch" href="../../assets/js/455.24cbebda.js"><link rel="prefetch" href="../../assets/js/456.a2f19b40.js"><link rel="prefetch" href="../../assets/js/457.27f4fb5a.js"><link rel="prefetch" href="../../assets/js/458.29941084.js"><link rel="prefetch" href="../../assets/js/459.b0cc6f89.js"><link rel="prefetch" href="../../assets/js/46.1f553681.js"><link rel="prefetch" href="../../assets/js/460.86ef4965.js"><link rel="prefetch" href="../../assets/js/461.c0b0f695.js"><link rel="prefetch" href="../../assets/js/462.8b86c3a9.js"><link rel="prefetch" href="../../assets/js/463.79aadbb4.js"><link rel="prefetch" href="../../assets/js/464.9735f749.js"><link rel="prefetch" href="../../assets/js/465.4bdede2b.js"><link rel="prefetch" href="../../assets/js/466.ef630311.js"><link rel="prefetch" href="../../assets/js/467.8664e027.js"><link rel="prefetch" href="../../assets/js/468.89b3d4ff.js"><link rel="prefetch" href="../../assets/js/469.74e0af2c.js"><link rel="prefetch" href="../../assets/js/47.5f78034c.js"><link rel="prefetch" href="../../assets/js/470.9643f84e.js"><link rel="prefetch" href="../../assets/js/471.e3a1e16a.js"><link rel="prefetch" href="../../assets/js/472.116791e2.js"><link rel="prefetch" href="../../assets/js/473.3bb6cb3d.js"><link rel="prefetch" href="../../assets/js/474.1a7a0724.js"><link rel="prefetch" href="../../assets/js/475.76c29d71.js"><link rel="prefetch" href="../../assets/js/476.fe1fd93a.js"><link rel="prefetch" href="../../assets/js/477.e3f203de.js"><link rel="prefetch" href="../../assets/js/478.b34f8b1c.js"><link rel="prefetch" href="../../assets/js/479.06d48874.js"><link rel="prefetch" href="../../assets/js/48.0c8a5846.js"><link rel="prefetch" href="../../assets/js/480.ffc77ad4.js"><link rel="prefetch" href="../../assets/js/481.2475d5aa.js"><link rel="prefetch" href="../../assets/js/482.5da370b4.js"><link rel="prefetch" href="../../assets/js/483.2531f6c1.js"><link rel="prefetch" href="../../assets/js/484.3f8b3ccf.js"><link rel="prefetch" href="../../assets/js/485.fb51e0ee.js"><link rel="prefetch" href="../../assets/js/486.881d8443.js"><link rel="prefetch" href="../../assets/js/487.36a959cb.js"><link rel="prefetch" href="../../assets/js/488.086e154c.js"><link rel="prefetch" href="../../assets/js/489.2afd2906.js"><link rel="prefetch" href="../../assets/js/49.40a46041.js"><link rel="prefetch" href="../../assets/js/490.a517239f.js"><link rel="prefetch" href="../../assets/js/491.c1f416dd.js"><link rel="prefetch" href="../../assets/js/492.e36de27b.js"><link rel="prefetch" href="../../assets/js/493.af28d057.js"><link rel="prefetch" href="../../assets/js/494.00509c64.js"><link rel="prefetch" href="../../assets/js/495.8ed86db6.js"><link rel="prefetch" href="../../assets/js/496.412e9f2d.js"><link rel="prefetch" href="../../assets/js/497.ed9f0eeb.js"><link rel="prefetch" href="../../assets/js/498.2112afec.js"><link rel="prefetch" href="../../assets/js/499.743df60a.js"><link rel="prefetch" href="../../assets/js/5.6f1dbbc3.js"><link rel="prefetch" href="../../assets/js/50.54de97a0.js"><link rel="prefetch" href="../../assets/js/500.ab62befa.js"><link rel="prefetch" href="../../assets/js/501.0d54ba9a.js"><link rel="prefetch" href="../../assets/js/502.2f3bf836.js"><link rel="prefetch" href="../../assets/js/503.c3473b0e.js"><link rel="prefetch" href="../../assets/js/504.cb511490.js"><link rel="prefetch" href="../../assets/js/505.a2cc8bdc.js"><link rel="prefetch" href="../../assets/js/506.f8ea663a.js"><link rel="prefetch" href="../../assets/js/507.9cc67e94.js"><link rel="prefetch" href="../../assets/js/508.e08708a1.js"><link rel="prefetch" href="../../assets/js/509.437502c3.js"><link rel="prefetch" href="../../assets/js/51.af5d6a98.js"><link rel="prefetch" href="../../assets/js/510.f5e8a583.js"><link rel="prefetch" href="../../assets/js/511.6fe511a5.js"><link rel="prefetch" href="../../assets/js/512.459d2d68.js"><link rel="prefetch" href="../../assets/js/513.a5f4a768.js"><link rel="prefetch" href="../../assets/js/514.5fd44c68.js"><link rel="prefetch" href="../../assets/js/515.c046ffb4.js"><link rel="prefetch" href="../../assets/js/516.a972f386.js"><link rel="prefetch" href="../../assets/js/517.7c804920.js"><link rel="prefetch" href="../../assets/js/518.ff4a2545.js"><link rel="prefetch" href="../../assets/js/519.b1a8d590.js"><link rel="prefetch" href="../../assets/js/52.b766b60a.js"><link rel="prefetch" href="../../assets/js/520.2d34cada.js"><link rel="prefetch" href="../../assets/js/521.f14247fe.js"><link rel="prefetch" href="../../assets/js/522.38b72172.js"><link rel="prefetch" href="../../assets/js/523.203fa4ac.js"><link rel="prefetch" href="../../assets/js/524.236cda03.js"><link rel="prefetch" href="../../assets/js/525.8caaad18.js"><link rel="prefetch" href="../../assets/js/526.9a217f1e.js"><link rel="prefetch" href="../../assets/js/527.06dc5a4f.js"><link rel="prefetch" href="../../assets/js/528.fa884c79.js"><link rel="prefetch" href="../../assets/js/529.d39c75ca.js"><link rel="prefetch" href="../../assets/js/53.eae65ff7.js"><link rel="prefetch" href="../../assets/js/530.65b18758.js"><link rel="prefetch" href="../../assets/js/531.85af388d.js"><link rel="prefetch" href="../../assets/js/532.9d3f253a.js"><link rel="prefetch" href="../../assets/js/533.77c2fa0b.js"><link rel="prefetch" href="../../assets/js/534.924b0eb2.js"><link rel="prefetch" href="../../assets/js/535.5854a4b0.js"><link rel="prefetch" href="../../assets/js/536.8b57b538.js"><link rel="prefetch" href="../../assets/js/537.ccb7ba0f.js"><link rel="prefetch" href="../../assets/js/538.b9c6c631.js"><link rel="prefetch" href="../../assets/js/539.63164d8a.js"><link rel="prefetch" href="../../assets/js/54.9b89b352.js"><link rel="prefetch" href="../../assets/js/540.7e721167.js"><link rel="prefetch" href="../../assets/js/541.0cd3f048.js"><link rel="prefetch" href="../../assets/js/542.6c5df759.js"><link rel="prefetch" href="../../assets/js/543.e1eebdf2.js"><link rel="prefetch" href="../../assets/js/544.a3042061.js"><link rel="prefetch" href="../../assets/js/545.1a468f89.js"><link rel="prefetch" href="../../assets/js/546.892c1841.js"><link rel="prefetch" href="../../assets/js/547.c6b5ef7e.js"><link rel="prefetch" href="../../assets/js/548.19d884b6.js"><link rel="prefetch" href="../../assets/js/549.7c34a773.js"><link rel="prefetch" href="../../assets/js/55.b8a1964e.js"><link rel="prefetch" href="../../assets/js/550.25f7d121.js"><link rel="prefetch" href="../../assets/js/551.b9f92580.js"><link rel="prefetch" href="../../assets/js/552.bf452147.js"><link rel="prefetch" href="../../assets/js/553.4815ac56.js"><link rel="prefetch" href="../../assets/js/554.c253ebb4.js"><link rel="prefetch" href="../../assets/js/555.4dbef2bf.js"><link rel="prefetch" href="../../assets/js/556.69f1a9f4.js"><link rel="prefetch" href="../../assets/js/557.679e8f40.js"><link rel="prefetch" href="../../assets/js/558.9515c7f8.js"><link rel="prefetch" href="../../assets/js/559.eb17cff7.js"><link rel="prefetch" href="../../assets/js/56.88fa6666.js"><link rel="prefetch" href="../../assets/js/560.0de96a04.js"><link rel="prefetch" href="../../assets/js/561.cdf49465.js"><link rel="prefetch" href="../../assets/js/562.2e895986.js"><link rel="prefetch" href="../../assets/js/563.40a31d36.js"><link rel="prefetch" href="../../assets/js/564.08f15bf2.js"><link rel="prefetch" href="../../assets/js/565.e7625c6a.js"><link rel="prefetch" href="../../assets/js/566.71ee556d.js"><link rel="prefetch" href="../../assets/js/567.7b3e4bc8.js"><link rel="prefetch" href="../../assets/js/568.1a3c07dc.js"><link rel="prefetch" href="../../assets/js/569.4c496338.js"><link rel="prefetch" href="../../assets/js/57.519e80e3.js"><link rel="prefetch" href="../../assets/js/570.d152813e.js"><link rel="prefetch" href="../../assets/js/571.e46946bd.js"><link rel="prefetch" href="../../assets/js/572.ae215a0d.js"><link rel="prefetch" href="../../assets/js/573.da7b2e6c.js"><link rel="prefetch" href="../../assets/js/574.f068c09e.js"><link rel="prefetch" href="../../assets/js/575.f2a128db.js"><link rel="prefetch" href="../../assets/js/576.caf5cd68.js"><link rel="prefetch" href="../../assets/js/577.b6c04041.js"><link rel="prefetch" href="../../assets/js/578.a7707d73.js"><link rel="prefetch" href="../../assets/js/579.ed17d056.js"><link rel="prefetch" href="../../assets/js/58.963c2309.js"><link rel="prefetch" href="../../assets/js/580.88a2ce36.js"><link rel="prefetch" href="../../assets/js/581.f99a65fa.js"><link rel="prefetch" href="../../assets/js/582.220ce66c.js"><link rel="prefetch" href="../../assets/js/583.5d42e8cc.js"><link rel="prefetch" href="../../assets/js/584.0737b3ce.js"><link rel="prefetch" href="../../assets/js/585.516b187d.js"><link rel="prefetch" href="../../assets/js/586.420c42c4.js"><link rel="prefetch" href="../../assets/js/587.e3deb3dd.js"><link rel="prefetch" href="../../assets/js/588.c9bfc1e3.js"><link rel="prefetch" href="../../assets/js/589.ee0f90f3.js"><link rel="prefetch" href="../../assets/js/59.d9b10f83.js"><link rel="prefetch" href="../../assets/js/590.ea859bba.js"><link rel="prefetch" href="../../assets/js/591.4b9781fd.js"><link rel="prefetch" href="../../assets/js/592.c9da8cab.js"><link rel="prefetch" href="../../assets/js/6.064acd80.js"><link rel="prefetch" href="../../assets/js/60.7e89993c.js"><link rel="prefetch" href="../../assets/js/61.f2039f26.js"><link rel="prefetch" href="../../assets/js/62.474d18a7.js"><link rel="prefetch" href="../../assets/js/63.3a64d334.js"><link rel="prefetch" href="../../assets/js/64.4a3787c2.js"><link rel="prefetch" href="../../assets/js/65.120ee13f.js"><link rel="prefetch" href="../../assets/js/66.e7ff207d.js"><link rel="prefetch" href="../../assets/js/67.55a68541.js"><link rel="prefetch" href="../../assets/js/68.33f8c7cd.js"><link rel="prefetch" href="../../assets/js/69.69d65c56.js"><link rel="prefetch" href="../../assets/js/7.ce2273f5.js"><link rel="prefetch" href="../../assets/js/70.93a544a5.js"><link rel="prefetch" href="../../assets/js/71.6eb8d306.js"><link rel="prefetch" href="../../assets/js/72.8cbae6a9.js"><link rel="prefetch" href="../../assets/js/73.c737f071.js"><link rel="prefetch" href="../../assets/js/74.d0ea9fc8.js"><link rel="prefetch" href="../../assets/js/75.2219607f.js"><link rel="prefetch" href="../../assets/js/76.278079e2.js"><link rel="prefetch" href="../../assets/js/77.88eadfbc.js"><link rel="prefetch" href="../../assets/js/78.257c919e.js"><link rel="prefetch" href="../../assets/js/79.e6f5d078.js"><link rel="prefetch" href="../../assets/js/8.e2571ee7.js"><link rel="prefetch" href="../../assets/js/80.40ba7856.js"><link rel="prefetch" href="../../assets/js/81.1fab2c8f.js"><link rel="prefetch" href="../../assets/js/82.6eaad50e.js"><link rel="prefetch" href="../../assets/js/83.9f3e6e81.js"><link rel="prefetch" href="../../assets/js/84.060f32c2.js"><link rel="prefetch" href="../../assets/js/85.c069396c.js"><link rel="prefetch" href="../../assets/js/86.ced213eb.js"><link rel="prefetch" href="../../assets/js/87.763c4879.js"><link rel="prefetch" href="../../assets/js/88.69fe1a6a.js"><link rel="prefetch" href="../../assets/js/89.b87612a8.js"><link rel="prefetch" href="../../assets/js/9.5f2fc60c.js"><link rel="prefetch" href="../../assets/js/90.6132ccb6.js"><link rel="prefetch" href="../../assets/js/91.27dbc3bd.js"><link rel="prefetch" href="../../assets/js/92.88832461.js"><link rel="prefetch" href="../../assets/js/93.0166bd69.js"><link rel="prefetch" href="../../assets/js/94.e29b12f1.js"><link rel="prefetch" href="../../assets/js/95.f1245827.js"><link rel="prefetch" href="../../assets/js/96.9c45438e.js"><link rel="prefetch" href="../../assets/js/97.e8783a06.js"><link rel="prefetch" href="../../assets/js/98.60628afa.js"><link rel="prefetch" href="../../assets/js/99.b3cb9d0f.js">
    <link rel="stylesheet" href="../../assets/css/0.styles.f7de6701.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="../../index.html" class="home-link router-link-active"><!----> <span class="site-name">代码重工</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <!----></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><!---->  <!----> </aside> <main class="page"> <div class="theme-default-content content__default"><p></p><div class="table-of-contents"><ul><li><a href="#_1、准备工作">1、准备工作</a><ul><li><a href="#_1下载所需-tar-包">①下载所需 tar 包</a></li><li><a href="#_2确认-gcc-是否已安装">②确认 gcc 是否已安装</a></li></ul></li><li><a href="#_2、安装-pcre">2、安装 PCRE</a></li><li><a href="#_3、安装环境依赖">3、安装环境依赖</a></li><li><a href="#_4、正式安装nginx">4、正式安装Nginx</a></li><li><a href="#_5、启动访问首页">5、启动访问首页</a><ul><li><a href="#_1启动-nginx-服务器">①启动 Nginx 服务器</a></li><li><a href="#_2访问-nginx-服务器">②访问 Nginx 服务器</a></li><li><a href="#_3停止-nginx-服务器">③停止 Nginx 服务器</a></li><li><a href="#_4重新加载配置文件">④重新加载配置文件</a></li></ul></li><li><a href="#_1、大致说明">1、大致说明</a></li><li><a href="#_2、全局块">2、全局块</a></li><li><a href="#_3、events-块">3、events 块</a></li><li><a href="#_4、http-块">4、http 块</a><ul><li><a href="#_1http-全局块">①http 全局块</a></li><li><a href="#_2server-块">②server 块</a></li></ul></li><li><a href="#_5、小结">5、小结</a></li><li><a href="#_1、概念">1、概念</a><ul><li><a href="#_1正向代理">①正向代理</a></li><li><a href="#_2反向代理">②反向代理</a></li></ul></li><li><a href="#_2、操作">2、操作</a><ul><li><a href="#_1简单配置">①简单配置</a></li><li><a href="#_2进阶配置">②进阶配置</a></li></ul></li><li><a href="#_1、概念">1、概念</a></li><li><a href="#_2、搭建">2、搭建</a><ul><li><a href="#_1计划">①计划</a></li><li><a href="#_2准备-tomcat">②准备 Tomcat</a></li><li><a href="#_3配置-nginx">③配置 Nginx</a></li></ul></li><li><a href="#_3、负载均衡策略">3、负载均衡策略</a><ul><li><a href="#_1轮询-默认">①轮询（默认）</a></li><li><a href="#_2权重">②权重</a></li><li><a href="#_3ip-hash">③ip_hash</a></li><li><a href="#_4fair">④fair</a></li><li><a href="#_5其他参数">⑤其他参数</a></li></ul></li><li><a href="#_1、概念">1、概念</a><ul><li><a href="#_1动态请求和静态请求">①动态请求和静态请求</a></li><li><a href="#_2实现方案">②实现方案</a></li></ul></li><li><a href="#_2、操作">2、操作</a><ul><li><a href="#_1准备工作">①准备工作</a></li><li><a href="#_2配置-nginx-访问动态资源">②配置 Nginx 访问动态资源</a></li><li><a href="#_3nginx-中的总体配置">③Nginx 中的总体配置</a></li></ul></li></ul></div><p></p> <h1 id="一、简介"><a href="#一、简介" class="header-anchor">#</a> 一、简介</h1> <p><img src="../../assets/img/img001.4a637d1b.png" alt="images"></p> <table><thead><tr><th>产地</th> <th>俄罗斯</th></tr></thead> <tbody><tr><td>父亲</td> <td>Igor Sysoev</td></tr> <tr><td>开发语言</td> <td>C</td></tr> <tr><td>生日</td> <td>第一个公开版本0.1.0发布于2004年10月4日</td></tr> <tr><td>特长</td> <td>能够支撑5万并发，CPU、内存资源占用小，运行稳定</td></tr></tbody></table> <p><img src="../../assets/img/img002.fa75eaab.jpg" alt="images"></p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>Nginx 名称来自于：engine X，意为“X 引擎”。主要功能包括：</p> <ul><li>提供 HTTP 服务。</li> <li>提供基于反向代理的负载均衡服务。</li> <li>提供动静分离服务。</li> <li>基于 Lua 脚本编写脚本程序提供缓存服务。</li> <li>还可以通过安装模块整合其他技术或提供特定功能，为数众多的 Nginx 模块构成了繁荣的 Nginx 生态。</li></ul> <p>国内网站使用 Nginx 有：百度、京东、新浪、网易、腾讯、淘宝等等。</p></div> <h1 id="二、nginx-安装"><a href="#二、nginx-安装" class="header-anchor">#</a> 二、Nginx 安装</h1> <h2 id="_1、准备工作"><a href="#_1、准备工作" class="header-anchor">#</a> 1、准备工作</h2> <h3 id="_1下载所需-tar-包"><a href="#_1下载所需-tar-包" class="header-anchor">#</a> ①下载所需 tar 包</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token function">wget</span> -P /opt http://nginx.org/download/nginx-1.12.2.tar.gz
<span class="token function">wget</span> -P /opt http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="_2确认-gcc-是否已安装"><a href="#_2确认-gcc-是否已安装" class="header-anchor">#</a> ②确认 gcc 是否已安装</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>gcc -v
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>如果没有安装，那么可以使用下面命令：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>yum <span class="token function">install</span> -y gcc-c++
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_2、安装-pcre"><a href="#_2、安装-pcre" class="header-anchor">#</a> 2、安装 PCRE</h2> <p>PCRE(Perl Compatible Regular Expressions)是一个Perl库，包括 Perl 兼容的正则表达式库。安装步骤如下：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment"># ●第一步：进入/opt目录</span>
<span class="token builtin class-name">cd</span> /opt

<span class="token comment"># ●第二步：解压到当前目录</span>
<span class="token function">tar</span> -zxvf pcre-8.37.tar.gz

<span class="token comment"># ●第三步：进入解压目录</span>
<span class="token builtin class-name">cd</span> /opt/pcre-8.37/

<span class="token comment"># ●第四步：生成Makefile文件</span>
./configure

<span class="token comment"># ●第五步：编译</span>
<span class="token function">make</span>

<span class="token comment"># ●第六步：安装</span>
<span class="token function">make</span> <span class="token function">install</span>

<span class="token comment"># ●第七步：验证</span>
pcre-config --version
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><h2 id="_3、安装环境依赖"><a href="#_3、安装环境依赖" class="header-anchor">#</a> 3、安装环境依赖</h2> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>yum -y <span class="token function">install</span> <span class="token function">make</span> zlib zlib-devel gcc-c++ libtool openssl openssl-devel
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_4、正式安装nginx"><a href="#_4、正式安装nginx" class="header-anchor">#</a> 4、正式安装Nginx</h2> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment"># ●第一步：进入/opt目录</span>
<span class="token builtin class-name">cd</span> /opt

<span class="token comment"># ●第二步：解压到当前目录</span>
<span class="token function">tar</span> -zxvf /opt/nginx-1.12.2.tar.gz

<span class="token comment"># ●第三步：进入解压目录</span>
<span class="token builtin class-name">cd</span> /opt/nginx-1.12.2

<span class="token comment"># ●第四步：生成Makefile文件</span>
./configure

<span class="token comment"># ●第五步：编译</span>
<span class="token function">make</span>

<span class="token comment"># ●第六步：安装</span>
<span class="token function">make</span> <span class="token function">install</span>

<span class="token comment"># ●第七步：验证</span>
/usr/local/nginx/sbin/nginx -v
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><p>安装完成后可以到 /usr/local/nginx 这里查看 Nginx 的安装目录：</p> <p><img src="" alt="images"></p> <h2 id="_5、启动访问首页"><a href="#_5、启动访问首页" class="header-anchor">#</a> 5、启动访问首页</h2> <h3 id="_1启动-nginx-服务器"><a href="#_1启动-nginx-服务器" class="header-anchor">#</a> ①启动 Nginx 服务器</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>/usr/local/nginx/sbin/nginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_2访问-nginx-服务器"><a href="#_2访问-nginx-服务器" class="header-anchor">#</a> ②访问 Nginx 服务器</h3> <p>Nginx 服务器默认监听 80 端口。</p> <p><img src="../../assets/img/img004.dd420b78.png" alt="iamges"></p> <h3 id="_3停止-nginx-服务器"><a href="#_3停止-nginx-服务器" class="header-anchor">#</a> ③停止 Nginx 服务器</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>/usr/local/nginx/sbin/nginx -s stop
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_4重新加载配置文件"><a href="#_4重新加载配置文件" class="header-anchor">#</a> ④重新加载配置文件</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>/usr/local/nginx/sbin/nginx -s reload
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h1 id="三、nginx-配置文件"><a href="#三、nginx-配置文件" class="header-anchor">#</a> 三、Nginx 配置文件</h1> <h2 id="_1、大致说明"><a href="#_1、大致说明" class="header-anchor">#</a> 1、大致说明</h2> <p>Nginx 包含很多配置文件，但是主要配置文件是：/usr/local/nginx/conf/nginx.conf。去掉全部注释后，配置文件的主体结构为：</p> <div class="language-conf line-numbers-mode"><pre class="language-text"><code>worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div><h2 id="_2、全局块"><a href="#_2、全局块" class="header-anchor">#</a> 2、全局块</h2> <p>从配置文件开始到 events 块之间的内容，主要会设置一些影响 Nginx 服务器整体运行的配置指令。主要包括配置运行 Nginx 服务器的用户（组）、允许生成的 worker process 数，进程 PID 文件存放路径、日志文件存放路径和类型以及配置文件的引入等。
比如上面第一行配置的：</p> <div class="language-conf line-numbers-mode"><pre class="language-text"><code>worker_processes  1;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>这是 Nginx 服务器并发处理服务的关键配置，<span style="color:blue;font-weight:bold;">worker_processes 值越大，可以支持的并发处理量也越多</span>，但是会受到硬件、软件等设备的<span style="color:blue;font-weight:bold;">制约</span>。</p> <p>配置举例：</p> <div class="language-conf line-numbers-mode"><pre class="language-text"><code>#user  nobody;
worker_processes  1;

# 错误日志文件保存的位置以及日志的级别
#error_log  logs/error.log;
error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

# PID 文件保存的位置
pid        logs/nginx.pid;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h2 id="_3、events-块"><a href="#_3、events-块" class="header-anchor">#</a> 3、events 块</h2> <p>events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接，常用的设置包括是否开启对多 work process 下的网络连接进行序列化，是否允许同时接收多个网络连接，选取哪种事件驱动模型来处理连接请求，每个 work process 可以同时支持的最大连接数等。这部分的配置对 Nginx 的性能影响较大，在实际中应该灵活配置。</p> <div class="language-conf line-numbers-mode"><pre class="language-text"><code>events {
    worker_connections  1024;
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>上述例子就表示每个 work process 支持的<span style="color:blue;font-weight:bold;">最大连接数</span>为 1024。</p> <p>当前 Nginx 服务器能够处理的并发请求数量 = 每个工作进程能够处理的最大连接数 × 工作进程数量</p> <h2 id="_4、http-块"><a href="#_4、http-块" class="header-anchor">#</a> 4、http 块</h2> <p>Nginx 服务器配置中最频繁的部分，代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。</p> <h3 id="_1http-全局块"><a href="#_1http-全局块" class="header-anchor">#</a> ①http 全局块</h3> <p>http 全局块配置的指令包括文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等。</p> <h3 id="_2server-块"><a href="#_2server-块" class="header-anchor">#</a> ②server 块</h3> <h4 id="_1-虚拟主机"><a href="#_1-虚拟主机" class="header-anchor">#</a> [1]虚拟主机</h4> <p>虚拟主机字面意思就是虚拟出来的主机。而这里的主机指的是网站服务器。小型、微型的网站考虑成本没有必要租用整台主机，所以虚拟主机提供了运行小型网站的基本配置，可以用来直接部署运行小型网站（PHP 网站或静态网站）。虚拟主机从用户角度看，和一台独立的硬件主机是完全一样的，该技术的产生是为了节省互联网服务器硬件成本。</p> <p>而 server 块就是主要负责配置虚拟主机。每个 http 块可以包括多个 server 块，而每个 server 块就相当于一个虚拟主机。</p> <p>每个 server 块又分成<span style="color:blue;font-weight:bold;">『全局块部分』</span>和 <span style="color:blue;font-weight:bold;">『location 块』</span>部分。</p> <h4 id="_2-server-全局块"><a href="#_2-server-全局块" class="header-anchor">#</a> [2]server 全局块</h4> <p>配置举例如下：</p> <div class="language-conf line-numbers-mode"><pre class="language-text"><code>    server {
    	# 本虚拟主机监听的端口号
        listen       80;
        
        # 本虚拟主机的名称
        server_name  localhost;

		# 本虚拟主机的字符集设置
        #charset koi8-r;

		# 本虚拟主机专属的访问日志设置
        #access_log  logs/host.access.log  main;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h4 id="_3-location-块"><a href="#_3-location-块" class="header-anchor">#</a> [3]location 块</h4> <p>一个 server 块可以配置多个 location 块。这块的主要作用是基于 Nginx  服务器接收到的请求字符串（例如 server_name/uri-string），对虚拟主机名称（也可以是IP别名）之外的字符串（例如 前面的 /uri-string）进行匹配，对特定的请求进行处理。地址定向、数据缓存和应答控制等功能，还有许多第三方模块的配置也在这里进行。</p> <p><img src="../../assets/img/img005.b74e8651.png" alt="images"></p> <h2 id="_5、小结"><a href="#_5、小结" class="header-anchor">#</a> 5、小结</h2> <p>配置文件结构：</p> <ul><li>全局块</li> <li>events 块</li> <li>http 块
<ul><li>http 全局块</li> <li>server 块（可以有多个）
<ul><li>server 全局块</li> <li>location 块（可以有多个）</li></ul></li></ul></li></ul> <h1 id="四、反向代理"><a href="#四、反向代理" class="header-anchor">#</a> 四、反向代理</h1> <h2 id="_1、概念"><a href="#_1、概念" class="header-anchor">#</a> 1、概念</h2> <h3 id="_1正向代理"><a href="#_1正向代理" class="header-anchor">#</a> ①正向代理</h3> <p>代理内网，访问外网</p> <p><img src="../../assets/img/img006.72b1673d.png" alt="images"></p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>局域网中只有一台电脑能够上外网，那么就在这台电脑上安装代理服务器端程序。不能上外网的电脑连到这个代理程序，通过代理服务器上外网。</p> <p>这里代理服务器做的是一个<span style="color:blue;font-weight:bold;">『请求转发』</span>的操作。</p></div> <h3 id="_2反向代理"><a href="#_2反向代理" class="header-anchor">#</a> ②反向代理</h3> <p>代理外网，访问内网。</p> <p><img src="../../assets/img/img007.f77eeb71.png" alt="images"></p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>其实客户端对代理是无感知的，因为客户端不需要任何配置就可以访问，我们只需要将请求发送到反向代理服务器，由反向代理服务器去选择目标服务器获取数据后，再返回给客户端，此时反向代理服务器和目标服务器对外就是一个服务器，<span style="color:blue;font-weight:bold;">暴露的是代理服务器地址，隐藏了真实服务器IP地址</span>。</p></div> <h2 id="_2、操作"><a href="#_2、操作" class="header-anchor">#</a> 2、操作</h2> <h3 id="_1简单配置"><a href="#_1简单配置" class="header-anchor">#</a> ①简单配置</h3> <p>让 Nginx 为 Tomcat 做代理，也就是通过 Nginx 访问 Tomcat。</p> <h4 id="_1-启动tomcat"><a href="#_1-启动tomcat" class="header-anchor">#</a> [1]启动Tomcat</h4> <p>在 Linux 系统中，Tomcat 的 tar 包解压即可启动。但是前提是必须正确配置了 JDK。JDK所需配置如下：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment"># 在/etc/profile文件末尾加入如下配置：</span>
<span class="token comment"># 声明 JAVA_HOME 环境变量，等号两边不能有空格</span>
<span class="token assign-left variable">JAVA_HOME</span><span class="token operator">=</span>/opt/jdk1.8.0_121

<span class="token comment"># 给 PATH 环境变量附加 $JAVA_HOME/bin 部分</span>
<span class="token comment"># $PATH 表示引用 PATH 环境变量以前的旧值</span>
<span class="token comment"># 使用英文冒号连接</span>
<span class="token comment"># $JAVA_HOME 表示对 JAVA_HOME 变量的引用</span>
<span class="token comment"># $JAVA_HOME/bin 表示指向可执行文件</span>
<span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token variable">$JAVA_HOME</span>/bin:<span class="token environment constant">$PATH</span>

<span class="token comment"># 发布</span>
<span class="token comment"># 发布是发布变量名，不是引用变量的值，所以前面不写 $ 符号</span>
<span class="token builtin class-name">export</span> JAVA_HOME <span class="token environment constant">PATH</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>启动 Tomcat 的命令：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>/opt/apache-tomcat-7.0.75/bin/startup.sh
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>通过浏览器访问：</p> <p><img src="../../assets/img/img008.f9528631.png" alt="images"></p> <h4 id="_2-配置nginx"><a href="#_2-配置nginx" class="header-anchor">#</a> [2]配置Nginx</h4> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token comment"># 实验一：配置简单的反向代理</span>
server <span class="token punctuation">{</span>
    <span class="token comment"># 监听的端口号</span>
    listen <span class="token number">1111</span><span class="token punctuation">;</span>
    
    <span class="token comment"># server_name 不仅仅是当前虚拟主机的名称，而且是要和请求地址的IP地址部分进行匹配</span>
    <span class="token comment"># localhost 和 127.0.0.1 都代表本机；也可以写域名。</span>
    server_name www.atguigu.shuai<span class="token punctuation">;</span>

    <span class="token comment"># 配置 location 部分</span>
    <span class="token comment"># / 代表域名（或IP地址）:端口号之后服务器的根目录</span>
    location / <span class="token punctuation">{</span>
        <span class="token comment"># proxy是代理的意思；pass是传送的意思；合起来，proxy_pass是请求转发的意思。</span>
        <span class="token comment"># 现在这个具体配置的意思就是 Nginx 接收到请求后，将这个请求转发给 Linux 本机的 Tomcat 服务器。</span>
        proxy_pass http://localhost:8080<span class="token punctuation">;</span>
        
        <span class="token comment"># index 配置默认的欢迎页</span>
        index index.jsp index.html index.htm<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p>编写配置文件时，注意 Nginx 要求的语法：</p> <ul><li>大括号必须成对出现。</li> <li>每一行单独的配置结尾都必须有分号。</li></ul> <p>如果分号缺失会提示：nginx: [emerg] unexpected &quot;}&quot; in /usr/local/nginx/conf/nginx.conf:136</p> <p>如果大括号缺失会提示：nginx: [emerg] unexpected end of file, expecting &quot;}&quot; in /usr/local/nginx/conf/nginx.conf:139</p></div> <h4 id="_3-配置域名映射"><a href="#_3-配置域名映射" class="header-anchor">#</a> [3]配置域名映射</h4> <p>本来应该是由 DNS 服务器来实现从域名到 IP 地址的映射。我们自己搭建 DNS 服务器又太麻烦，所以我们直接在 Windows 本地来直接配置。</p> <p>这个功能本来应该通过 C:\Windows\System32\drivers\etc 文件来配置。但是这个文件所在目录很深，又需要管理员权限，所以操作很不方便。所以借助一个工具软件完成：SwitchHosts.exe</p> <p><img src="" alt="images"></p> <p><img src="../../assets/img/img010.12e6e141.png" alt="images"></p> <h3 id="_2进阶配置"><a href="#_2进阶配置" class="header-anchor">#</a> ②进阶配置</h3> <p>location 块的进一步语法：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>location <span class="token punctuation">[</span> <span class="token operator">=</span> <span class="token operator">|</span> ~ <span class="token operator">|</span> ~* <span class="token operator">|</span> ^~ <span class="token punctuation">]</span> uri <span class="token punctuation">{</span>

<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>1、= ：用于不含正则表达式的 uri 前，要求请求字符串与 uri 严格匹配，如果匹配成功，就停止继续向下搜索并立即处理该请求。所谓继续向下搜索是指继续查找下面的 location。</p> <p>2、~：用于表示 uri <span style="color:blue;font-weight:bold;">包含正则表达式</span>，并且<span style="color:blue;font-weight:bold;">区分</span>大小写。</p> <p>3、~*：用于表示 uri <span style="color:blue;font-weight:bold;">包含正则表达式</span>，并且<span style="color:blue;font-weight:bold;">不区分</span>大小写。</p> <p>4、^~：用于<span style="color:blue;font-weight:bold;">不含正则表达式</span>的 uri 前，要求 Nginx 服务器找到标识 uri 和请求字符串匹配度最高的 location 后，立即使用此 location 处理请求，而不再使用 location 块中的正则 uri 和请求字符串做匹配。</p> <p>注意：如果 uri 包含正则表达式，则必须要有 ~ 或者 ~* 标识。</p></div> <h4 id="_1-使用等号的情况"><a href="#_1-使用等号的情况" class="header-anchor">#</a> [1]使用等号的情况</h4> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># 实验二：使用=形式的location</span>
    server <span class="token punctuation">{</span>
        listen <span class="token number">2222</span><span class="token punctuation">;</span>
        server_name www.atguigu.shuai<span class="token punctuation">;</span>

        <span class="token comment"># = 号表示请求地址和后面的 / 完全相等时，匹配当前location</span>
        location <span class="token operator">=</span> / <span class="token punctuation">{</span>
            proxy_pass http://localhost:8080<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>效果是：能够访问 Tomcat 首页，其他资源无法访问。</p> <p><img src="" alt="images"></p> <h4 id="_2-使用正则表达式的情况"><a href="#_2-使用正则表达式的情况" class="header-anchor">#</a> [2]使用正则表达式的情况</h4> <h5 id="_1-配置tomcat"><a href="#_1-配置tomcat" class="header-anchor">#</a> (1)配置Tomcat</h5> <p>启动两个 Tomcat，为了端口号不重复，需要设计两套：</p> <p>Tomcat A：8180、8105、8109</p> <p>Tomcat B：8280、8205、8209</p> <p>具体操作是：</p> <ul><li><p>先把纯净的 Tomcat 解压目录复制出来两套。</p></li> <li><p>分别修改两个 Tomcat 的端口号。</p></li> <li><p>然后在 webapps 目录下根据测算需要创建所需资源。</p></li></ul> <p>最终需要达到的效果是有如下访问地址：</p> <p>http://192.168.198.100:8180/aaa/one/</p> <p>http://192.168.198.100:8180/aaa/two/</p> <p>http://192.168.198.100:8280/bbb/one/</p> <p>http://192.168.198.100:8280/bbb/two/</p> <h5 id="_2-配置nginx-2"><a href="#_2-配置nginx-2" class="header-anchor">#</a> (2)配置Nginx</h5> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># 实验三：使用~匹配正则表达式的location</span>
    server <span class="token punctuation">{</span>
        listen <span class="token number">3333</span><span class="token punctuation">;</span>
        server_name www.atguigu.shuai<span class="token punctuation">;</span>
    
        <span class="token comment"># ~ 表示解析后面 URI 地址中的正则表达式</span>
        <span class="token comment"># 这里要求先有可以访问的资源，然后再用正则表达式匹配资源的访问地址</span>
        location ~ /aaa/ <span class="token punctuation">{</span>
            proxy_pass http://localhost:8180<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    
        location ~ /bbb/ <span class="token punctuation">{</span>
            proxy_pass http://localhost:8280<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>通过 Nginx 访问 Tomcat 资源时使用的地址：</p> <p>http://www.atguigu.shuai:3333/aaa/one/</p> <p>http://www.atguigu.shuai:3333/aaa/two/</p> <p>http://www.atguigu.shuai:3333/bbb/one/</p> <p>http://www.atguigu.shuai:3333/bbb/two/</p> <h4 id="_3-不用正则表达式的情况"><a href="#_3-不用正则表达式的情况" class="header-anchor">#</a> [3]不用正则表达式的情况</h4> <p>Tomcat 还是访问实验一的 8080 的 Tomcat。下面是 Nginx 的配置：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># 实验四：测试 ^~ 符号，表示不匹配正则表达式的情况</span>
    server <span class="token punctuation">{</span>
        listen <span class="token number">4444</span><span class="token punctuation">;</span>
        server_name www.atgugu.shuai<span class="token punctuation">;</span>

        <span class="token comment"># 表示匹配 / 地址，而且可以访问 / 下的资源</span>
        location ^~ / <span class="token punctuation">{</span>
            proxy_pass http://localhost:8080<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h1 id="五、负载均衡"><a href="#五、负载均衡" class="header-anchor">#</a> 五、负载均衡</h1> <h2 id="_1、概念-2"><a href="#_1、概念-2" class="header-anchor">#</a> 1、概念</h2> <p>访问量太大，一个 Tomcat 扛不住，所以就搭建 Tomcat 集群。让集群中的多个 Tomcat 服务器实例<span style="color:blue;font-weight:bold;">分担负载</span>。</p> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>纵向扩容和横向扩容：</p> <ul><li>纵向扩容：给单台服务器提升硬件的配置。例如：提升 CPU、增加内存、扩大带宽、扩大硬盘容量等等。有极限存在，很容易就达到瓶颈。所以系统整体的性能不能单独靠纵向扩容来实现。</li> <li>横向扩容：为了更进一步突破系统整体的瓶颈，增加服务器实例，构成<span style="color:blue;font-weight:bold;">集群</span>，实现横向扩容。</li></ul> <p>集群和分布式：</p> <ul><li>相同点：都需要用到多台服务器</li> <li>不同点：
<ul><li>集群 cluster（同构）：每个服务器实例上运行的是项目的同一个模块</li> <li>分布式 distribution（异构）：项目整体拆分模块后，每个模块在自己独立的服务器上运行，而且模块之间可以互相访问</li></ul></li></ul></div> <h2 id="_2、搭建"><a href="#_2、搭建" class="header-anchor">#</a> 2、搭建</h2> <h3 id="_1计划"><a href="#_1计划" class="header-anchor">#</a> ①计划</h3> <p><img src="" alt="images"></p> <h3 id="_2准备-tomcat"><a href="#_2准备-tomcat" class="header-anchor">#</a> ②准备 Tomcat</h3> <p>略</p> <h3 id="_3配置-nginx"><a href="#_3配置-nginx" class="header-anchor">#</a> ③配置 Nginx</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># 实验五：测试负载均衡</span>
    server <span class="token punctuation">{</span>
        listen <span class="token number">5555</span><span class="token punctuation">;</span>
        server_name www.atguigu.shuai<span class="token punctuation">;</span>
        location / <span class="token punctuation">{</span>
            proxy_pass http://yanzu_balance<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment"># upstream 代表上游服务器</span>
    upstream yanzu_balance <span class="token punctuation">{</span>
        server localhost:8180<span class="token punctuation">;</span>
        server localhost:8280<span class="token punctuation">;</span>
        server localhost:8380<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="_3、负载均衡策略"><a href="#_3、负载均衡策略" class="header-anchor">#</a> 3、负载均衡策略</h2> <h3 id="_1轮询-默认"><a href="#_1轮询-默认" class="header-anchor">#</a> ①轮询（默认）</h3> <p>每个请求按时间顺序逐一分配到不同的后端服务器，如果后端服务器down掉，能自动剔除。</p> <p><img src="../../assets/img/img013.aa8369a0.png" alt="images"></p> <h3 id="_2权重"><a href="#_2权重" class="header-anchor">#</a> ②权重</h3> <p>权重越高的服务器实例，分担越大的负载量。所以硬件配置较好的服务器应该设置较高的权重。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># upstream 代表上游服务器</span>
    upstream yanzu_balance <span class="token punctuation">{</span>
        <span class="token comment"># 负载均衡策略：weight 配置指定当前服务器实例的权重</span>
        server localhost:8180 <span class="token assign-left variable">weight</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
        server localhost:8280 <span class="token assign-left variable">weight</span><span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">;</span>
        server localhost:8380 <span class="token assign-left variable">weight</span><span class="token operator">=</span><span class="token number">70</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p><img src="../../assets/img/img014.cdb44ba7.png" alt="images"></p> <h3 id="_3ip-hash"><a href="#_3ip-hash" class="header-anchor">#</a> ③ip_hash</h3> <p>根据每个请求的 IP 地址，进行哈希运算，得到一个固定值。再根据这个固定值，唯一定位到一个具体的服务器实例。这样一来，这个用户的请求就是由一个固定的服务器实例来处理。</p> <ul><li>优势：没有 Session 不一致问题。</li> <li>局限性：固定服务器实例如果宕机，那么这台服务器上保存的 Session 信息会丢失。</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># upstream 代表上游服务器</span>
    upstream yanzu_balance <span class="token punctuation">{</span>

        <span class="token comment"># 负载均衡策略：ip_hash，固定ip由固定服务器实例处理</span>
        ip_hash<span class="token punctuation">;</span>
        server localhost:8180<span class="token punctuation">;</span>
        server localhost:8280<span class="token punctuation">;</span>
        server localhost:8380<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img src="../../assets/img/img015.ce278ac3.png" alt="images"></p> <h3 id="_4fair"><a href="#_4fair" class="header-anchor">#</a> ④fair</h3> <p>需要借助其他 Nginx 模块实现功能。fair 采用的不是内建负载均衡使用的轮换的均衡算法，而是可以根据页面大小、加载时间长短智能的进行负载均衡。需额外安装模块。最终效果是能够按后端服务器的响应时间来分配请求，响应时间短的优先分配。</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    upstream yanzu_balance <span class="token punctuation">{</span>

        <span class="token comment"># 负载均衡策略：fair</span>
        fair<span class="token punctuation">;</span>
        server localhost:8180<span class="token punctuation">;</span>
        server localhost:8280<span class="token punctuation">;</span>
        server localhost:8380<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="_5其他参数"><a href="#_5其他参数" class="header-anchor">#</a> ⑤其他参数</h3> <ul><li>down</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    upstream yanzu_balance <span class="token punctuation">{</span>
        server localhost:8180 down<span class="token punctuation">;</span>
        server localhost:8280<span class="token punctuation">;</span>
        server localhost:8380<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>表示当前服务器实例处于宕机状态，不工作，不参与负载均衡。</p> <ul><li>backup</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    upstream yanzu_balance <span class="token punctuation">{</span>
        server localhost:8180<span class="token punctuation">;</span>
        server localhost:8280 backup<span class="token punctuation">;</span>
        server localhost:8380<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>表示当前服务器是备份机，在其他非备份机停止工作时，才工作。所以通常情况下它的负载压力最小。</p> <h1 id="六、动静分离"><a href="#六、动静分离" class="header-anchor">#</a> 六、动静分离</h1> <h2 id="_1、概念-3"><a href="#_1、概念-3" class="header-anchor">#</a> 1、概念</h2> <h3 id="_1动态请求和静态请求"><a href="#_1动态请求和静态请求" class="header-anchor">#</a> ①动态请求和静态请求</h3> <ul><li>动态请求：需要由 Java 程序来处理的请求。</li> <li>静态请求：访问静态资源，不需要 Java 程序处理的请求。</li></ul> <h3 id="_2实现方案"><a href="#_2实现方案" class="header-anchor">#</a> ②实现方案</h3> <ul><li>方案一：纯粹把静态文件独立成单独的域名，放在独立的服务器上，也是目前主流推崇的方案。</li> <li>方案二：动态跟静态文件混合在一起发布，通过 Nginx 来分开。</li></ul> <h2 id="_2、操作-2"><a href="#_2、操作-2" class="header-anchor">#</a> 2、操作</h2> <h3 id="_1准备工作"><a href="#_1准备工作" class="header-anchor">#</a> ①准备工作</h3> <ul><li><p>在 Linux 系统中创建目录用来保存静态资源文件。</p> <ul><li>/data/images/mi.jpg</li> <li>/data/www/index.html</li></ul></li> <li><p>在 Nginx 中配置对这些静态资源的映射</p></li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># 实验六：动静分离</span>
    <span class="token comment"># 配置对静态资源的映射</span>
    server <span class="token punctuation">{</span>
        listen <span class="token number">7777</span><span class="token punctuation">;</span>
        server_name www.atguigu.shuai<span class="token punctuation">;</span>

        location / <span class="token punctuation">{</span>
            root html<span class="token punctuation">;</span>
            index index.html<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment"># 当用户通过 Nginx 访问 /images/ 目录下的内容时，参考这个 location 配置</span>
        location /images/ <span class="token punctuation">{</span>
            <span class="token comment"># root 表示指定静态资源所在的根目录 </span>
            root /data/<span class="token punctuation">;</span>

            <span class="token comment"># 开启 autoindex 功能，可以在页面上显示目录的内容</span>
            autoindex on<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment"># 当用户通过 Nginx 访问 /www/ 目录下的内容时，参考这个 location 配置</span>
        location /www/ <span class="token punctuation">{</span>
            root /data/<span class="token punctuation">;</span>
            autoindex on<span class="token punctuation">;</span>
            index index.html index.htm<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div><ul><li>在 Tomcat 中准备 JSP 页面</li></ul> <div class="language-jsp line-numbers-mode"><pre class="language-text"><code>&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

    &lt;h1&gt;JSP 页面&lt;/h1&gt;
    &lt;img src=&quot;/images/mi.jpg&quot; /&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>现在在这个 JSP 页面中，/images/mi.jpg 路径并不是按照 Tomcat 上运行的 Web 应用来编写的。而是按照通过 Nginx 访问静态资源的规则，编写的路径。</p> <h3 id="_2配置-nginx-访问动态资源"><a href="#_2配置-nginx-访问动态资源" class="header-anchor">#</a> ②配置 Nginx 访问动态资源</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>        <span class="token comment"># 配置 location 访问 Tomcat</span>
        location / <span class="token punctuation">{</span>
            proxy_pass http://localhost:8080<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><img src="../../assets/img/img016.57dd7a48.png" alt="images"></p> <h3 id="_3nginx-中的总体配置"><a href="#_3nginx-中的总体配置" class="header-anchor">#</a> ③Nginx 中的总体配置</h3> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>    <span class="token comment"># 实验六：动静分离</span>
    <span class="token comment"># 配置对静态资源的映射</span>
    server <span class="token punctuation">{</span>
        listen <span class="token number">7777</span><span class="token punctuation">;</span>
        server_name www.atguigu.shuai<span class="token punctuation">;</span>

        <span class="token comment"># 配置 location 访问 Tomcat</span>
        location / <span class="token punctuation">{</span>
            proxy_pass http://localhost:8080<span class="token punctuation">;</span>
            index index.jsp<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment"># 当用户通过 Nginx 访问 /images/ 目录下的内容时，参考这个 location 配置</span>
        location /images/ <span class="token punctuation">{</span>
            <span class="token comment"># root 表示指定静态资源所在的根目录 </span>
            root /data/<span class="token punctuation">;</span>

            <span class="token comment"># 开启 autoindex 功能，可以在页面上显示目录的内容</span>
            autoindex on<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment"># 当用户通过 Nginx 访问 /www/ 目录下的内容时，参考这个 location 配置</span>
        location /www/ <span class="token punctuation">{</span>
            root /data/<span class="token punctuation">;</span>
            autoindex on<span class="token punctuation">;</span>
            index index.html index.htm<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br></div></div><p><a href="../../index-2.html">回首页</a></p></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="../../assets/js/app.972bd0f0.js" defer></script><script src="../../assets/js/4.904e76b5.js" defer></script><script src="../../assets/js/16.87793b5d.js" defer></script>
  </body>

<!-- Mirrored from heavy_code_industry.gitee.io/code_heavy_industry/pro009-Nginx/snapshot/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 10 May 2022 04:34:46 GMT -->
</html>
